package com.pan.test.controller;

import com.pan.test.entity.vo.ResponseVO;
import com.pan.test.service.RechargeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/recharge")
public class RechargeController {

    @Resource
    private RechargeService rechargeService;

    @PostMapping("/create")
    public ResponseVO<Map<String, Object>> createRechargeOrder(@RequestBody Map<String, Object> params) {
        Double amount = Double.parseDouble(params.get("amount").toString());
        String paymentMethod = (String) params.get("paymentMethod");
        
        // 这里调用充值服务创建订单
        Map<String, Object> result = rechargeService.createOrder(amount, paymentMethod);
        return ResponseVO.success(result);
    }

    @GetMapping("/records")
    public ResponseVO<Map<String, Object>> getRechargeRecords(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        Map<String, Object> result = rechargeService.getRechargeRecords(pageNum, pageSize);
        return ResponseVO.success(result);
    }

    @GetMapping("/callback/{orderId}")
    public ResponseVO<Void> handlePaymentCallback(@PathVariable String orderId) {
        // 处理支付回调
        rechargeService.handlePaymentCallback(orderId);
        return ResponseVO.success();
    }
} 